package com.acim.mobile.app.manager
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.geom.Point;
	
	import org.taomee.utils.DisplayUtil;

	/**
	 * 手机应用层管理
	 * @author Tide
	 */
	public class LayerManager
	{
		public static const stageWidth:int = 0;
		public static const stageHeight:int = 0;
		
		//根
		private static var _root:Sprite;
		private static var _stage:Stage;
		
		//应用层
		private static var _appLevel:Sprite;
		//顶层:特殊情况使用的层级
		private static var _topLevel:Sprite;
		//界面层
		private static var _uiLevel:Sprite;
		//工具层
		private static var _toolsLevel:Sprite;
		//深度交换层
		private static var _depthLevel:Sprite;
		//背景层
		private static var _bgLevel:Sprite;
		
		public static function setup(context:Sprite):void
		{
			_root = context;
			_stage = _root.stage;
			//0层  背景层
			_bgLevel = new Sprite();
			_bgLevel.mouseEnabled = false;
			_bgLevel.name = "bgLevel";
			_root.addChild(_bgLevel);
			//1层 交换层
			_depthLevel = new Sprite();
			_depthLevel.mouseEnabled = false;
			_depthLevel.name = "depthLevel";
			_root.addChild(_depthLevel);
			//2层 UI层
			_uiLevel = new Sprite();
			_uiLevel.mouseEnabled = false;
			_uiLevel.name = "uiLevel";
			_root.addChild(_uiLevel);
			//3层 工具层
			_toolsLevel = new Sprite();
			_toolsLevel.mouseEnabled = false;
			_toolsLevel.name = "toolLevel";
			_root.addChild(_toolsLevel);
			//4层  应用层
			_appLevel = new Sprite();
			_appLevel.mouseEnabled = true;
			_appLevel.name = "appLevel";
			_root.addChild(_appLevel);
			//5层 顶层
			_topLevel = new Sprite();
			_topLevel.mouseEnabled = false;
			_topLevel.name = "topLevel";
			_root.addChild(_topLevel);
		}
		
		//---------------------------------------------------------------
		// public function
		//---------------------------------------------------------------
		
		/**
		 * 获取舞台中心点
		 * @return 
		 */
		public static function get stageCenterPoint():Point
		{
			return new Point(stageWidth/2,stageHeight/2);
		}
		
		/**
		 * 开启鼠标事件
		 */
		public static function openMouseEvent():void
		{
			_depthLevel.mouseChildren = true;
			_uiLevel.mouseChildren = true;
			_toolsLevel.mouseChildren = true;
			_appLevel.mouseChildren = true;
			_topLevel.mouseChildren = true;
			_bgLevel.mouseChildren = true;
		}
		
		/**
		 * 关闭鼠标事件
		 * @param isTools 是否禁止Top层，默认为false
		 * @param isTop
		 */
		public static function closeMouseEvent(isTools:Boolean = true, isTop:Boolean = false):void
		{
			_depthLevel.mouseChildren = false;
			_uiLevel.mouseEnabled = false;
			if(isTools)
			{
				_toolsLevel.mouseChildren = false;
			}
			_appLevel.mouseChildren = false;
			if(isTop)
			{
				_topLevel.mouseChildren = false;
			}
			_bgLevel.mouseChildren = false;
		}
		
		/**
		 * 显示内容层
		 */
		public static function show():void
		{
			_root.addChild(_bgLevel);
			_root.addChild(_depthLevel);
			_root.addChild(_uiLevel);
			_root.addChild(_toolsLevel);
			_root.addChild(_appLevel);
			_root.addChild(_topLevel);
		}
		
		/**
		 * 隐藏内容层，为应用层加速
		 */
		public static function hide():void
		{
			DisplayUtil.removeForParent(_bgLevel,false);
			DisplayUtil.removeForParent(_depthLevel,false);
			DisplayUtil.removeForParent(_uiLevel,false);
			DisplayUtil.removeForParent(_toolsLevel,false);
		}
		
		//---------------------------------------------------------------
		// setter and getter
		//---------------------------------------------------------------
		
		public static function get bgLevel():Sprite
		{
			return _bgLevel;
		}
		
		public static function get depthLevel():Sprite
		{
			return _depthLevel;
		}
		
		public static function get toolsLevel():Sprite
		{
			return _toolsLevel;
		}
		
		public static function get uiLevel():Sprite
		{
			return _uiLevel;
		}
		
		public static function get topLevel():Sprite
		{
			return _topLevel;
		}
		
		public static function get appLevel():Sprite
		{
			return _appLevel;
		}
	}
}